<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>promise语法</title>
</head>
<body>
    <!--
    -->
</body>
<script>
  let checkLogin = function(){
    return new Promise(function (resolve,reject) {
      let flag = document.cookie.indexOf("userI")>-1?true:false;
      if(flag = true){
        resolve({
          status:0,
          result:true
        })
      }else{
        reject('error');
      }
    })
  };
  checkLogin().then( res =>{
    if(res.status == 0){
      console.log('login success');
      return getUseriInfo();
    }
  }).catch(error => {
    console.log(`error: ${error}`)
  })
  let getUseriInfo = () =>{
    return new Promise((resolve,reject) => {
      let userInfo = {
         userId:'101'
      }
      resolve(userInfo);
    });
  }
</script>
</html>
